import { t } from 'i18next'
import React, { useMemo } from 'react'
import LabelCheckBox from '../components/LabelCheckBox'
import { IMccOperation } from '@/api/personalConfig/interface'
import { IAction } from '../interface'
import { useGlobalStore } from '@/store/global'
import shallow from 'zustand/shallow'
interface CommonOperationsProps {
	configInfo: IMccOperation
	defaultInfo: IMccOperation
	propsChange: ({ type, payLoad }: IAction) => void
}
/*
组件的使用
<CommonOperations
	configInfo={personalConfigInfo.mcc_operate}
	defaultInfo={defaultPersonalConfig.mcc_operate}
	propsChange={dispatch}
></CommonOperations>
*/
export default function CommonOperations({ configInfo, defaultInfo, propsChange }: CommonOperationsProps) {
	const { user, SWITCH } = useGlobalStore((state) => ({ user: state.user, SWITCH: state.SWITCH }), shallow)
	let defaultValue: string[] = useMemo(() => {
		let arr: string[] = []
		defaultInfo &&
			(Object.keys(defaultInfo) as Array<keyof IMccOperation>).forEach((key) => {
				if (defaultInfo[key]) {
					arr.push(key)
				}
			})
		return arr
	}, [defaultInfo])
	const commonSettings = [
		{
			text: t('邀请终端'),
			value: 'mt_add',
			checked: configInfo.mt_add,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtAdd', payLoad: val })
			},
		},
		{
			text: t('呼叫全部离线'),
			value: 'mt_add_all',
			checked: configInfo.mt_add_all,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtAddAll', payLoad: val })
			},
		},
		{
			text: t('VIP设置'),
			value: 'vip',
			checked: configInfo.vip,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setVip', payLoad: val })
			},
		},
		{
			text: t('全场哑音'),
			value: 'mute',
			checked: configInfo.mute,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccMute', payLoad: val })
			},
		},
		{
			text: t('全场静音'),
			value: 'silence',
			checked: configInfo.silence,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccSilence', payLoad: val })
			},
		},
		{
			text: t('终端选看'),
			value: 'mt_select',
			checked: configInfo.mt_select,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtSelect', payLoad: val })
			},
		},
		{
			text: t('会议画面合成'),
			value: 'vmp',
			checked: configInfo.vmp,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccVmp', payLoad: val })
			},
		},
		{
			text: t('管理方画面合成'),
			value: 'mtvmp',
			checked: configInfo.mtvmp,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccMtVmp', payLoad: val })
			},
		},
		{
			text: t('混音'),
			value: 'mix',
			checked: configInfo.mix,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccMix', payLoad: val })
			},
		},
		{
			text: t('电视墙'),
			value: 'tvwall',
			checked: configInfo.tvwall,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setTVWall', payLoad: val })
			},
			hide: !SWITCH.tvwall,
		},
		{
			text: t('会议轮询'),
			value: 'meeting_poll',
			checked: configInfo.meeting_poll,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMeetingPoll', payLoad: val })
			},
		},
		{
			text: t('管理方轮询'),
			value: 'chairman_poll',
			checked: configInfo.chairman_poll,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setChairmanPoll', payLoad: val })
			},
		},
		{
			text: t('点名轮询'),
			value: 'rollcall',
			checked: configInfo.rollcall,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setRollCall', payLoad: val })
			},
		},
		{
			text: t('批量删除终端'),
			value: 'mt_batch_delete',
			checked: configInfo.mt_batch_delete,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtBatchDelete', payLoad: val })
			},
		},
		{
			text:
				user?.enable_video && user?.enable_live && SWITCH.vrs.video && SWITCH.vrs.live
					? t('录播与直播')
					: user?.enable_video && SWITCH.vrs.video
					? t('会议录像')
					: user?.enable_live && SWITCH.vrs.live
					? t('会议直播')
					: t('录播与直播'),
			value: 'video_live',
			checked: configInfo.video_live,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setVideoLive', payLoad: val })
			},
			hide: (!user?.enable_video || !SWITCH.vrs.video) && (!user?.enable_live || !SWITCH.vrs.live),
		},
		{
			text: t('会议放像'),
			value: 'meeting_video',
			checked: configInfo.meeting_video,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMeetingVideo', payLoad: val })
			},
			hide: !user?.enable_play || !SWITCH.vrs.playVideo,
		},
		{
			text: t('批量挂断终端'),
			value: 'mt_batch_offline',
			checked: configInfo.mt_batch_offline,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtBatchOffline', payLoad: val })
			},
		},
		{
			text: t('短消息'),
			value: 'msg',
			checked: configInfo.msg,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMsg', payLoad: val })
			},
		},
		{
			text: t('开启强制广播', { context: 'SC1' }),
			value: 'broadcast',
			checked: configInfo.broadcast,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setBroadcast', payLoad: val })
			},
		},
		{
			text: t('语音激励'),
			value: 'voice_inspire',
			checked: configInfo.voice_inspire,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setVoiceInspire', payLoad: val })
			},
		},
		{
			text: t('上传轮询'),
			value: 'upload',
			checked: configInfo.upload,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccUpload', payLoad: val })
			},
		},
		{
			text: t('开启/关闭数据协作'),
			value: 'data_meeting',
			checked: configInfo.data_meeting,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setDataMeeting', payLoad: val })
			},
			hide: !user?.enable_dcs || !SWITCH.dcs,
		},
		{
			text: t('终端录像'),
			value: 'mt_record',
			checked: configInfo.mt_record,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMtRecord', payLoad: val })
			},
			hide: !user?.enable_video || !SWITCH.vrs.video,
		},
		{
			text: t('追呼设置'),
			value: 'recall',
			checked: configInfo.recall,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMccRecall', payLoad: val })
			},
		},
		{
			text: t('会议空间'),
			value: 'file_manage',
			checked: configInfo.file_manage,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setFileManage', payLoad: val })
			},
			hide: !SWITCH.meetingSpace,
		},
		{
			text: t('会议监控'),
			value: 'monitor',
			checked: configInfo.monitor,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setMonitor', payLoad: val })
			},
			hide: !SWITCH.monitor,
		},
		{
			text: 'AI',
			value: 'ai',
			checked: configInfo.ai,
			onChange: (val: 0 | 1) => {
				propsChange({ type: 'setAI', payLoad: val })
			},
			hide: !SWITCH.kis.ai,
		},
	]
	return (
		<LabelCheckBox
			mainDesc={t('选中常用功能')}
			subDesc={t('勾选后常用功能中会出现对应的功能，最多选15项')}
			list={commonSettings}
			defaultValue={defaultValue}
			maxLimit={15}
		></LabelCheckBox>
	)
}
